package com.ldzg.blockwatcher.risk;

import com.ldzg.blockwatcher.config.risk.RiskProperties;
import com.ldzg.blockwatcher.risk.dto.TransactionInfo;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 18310740596@163.com
 * @version V1.0.0
 * @since 2025-07-05 11:22:19
 */
public abstract class AbstractRiskRule implements IRiskRule {

    @Autowired
    private RiskProperties riskProperties;

    @Override
    public int getScore(TransactionInfo transactionInfo) {
        RiskProperties.RuleConfig ruleConfig = riskProperties.getRules().get(this.getClass().getSimpleName());
        if (ruleConfig == null || !ruleConfig.isEnabled()) {
            return 0;
        }

        if (doCheck(transactionInfo)) {
            return ruleConfig.getScore();
        }

        return 0;
    }

    /**
     *  执行检查
     *
     * @param transactionInfo 交易信息
     * @return 是否命中规则
     */
    protected abstract boolean doCheck(TransactionInfo transactionInfo);
}